package io.renren.com.qywt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.com.qywt.entity.AftersaleLocationFeeEntity;
import io.renren.commons.mybatis.service.impl.CrudServiceImpl;
import io.renren.com.qywt.dao.AftersalePurchasereturnFeeDao;
import io.renren.com.qywt.dto.AftersalePurchasereturnFeeDTO;
import io.renren.com.qywt.entity.AftersalePurchasereturnFeeEntity;
import io.renren.com.qywt.service.AftersalePurchasereturnFeeService;
import io.renren.commons.security.context.TenantContext;
import io.renren.commons.security.user.SecurityUser;
import io.renren.commons.security.user.UserDetail;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 退供费明细表
 *
 * @author jiaohj 15110414840@139.com
 * @since 3.0 2022-08-10
 */
@Service
public class AftersalePurchasereturnFeeServiceImpl extends CrudServiceImpl<AftersalePurchasereturnFeeDao, AftersalePurchasereturnFeeEntity, AftersalePurchasereturnFeeDTO> implements AftersalePurchasereturnFeeService {

    @Override
    public QueryWrapper<AftersalePurchasereturnFeeEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<AftersalePurchasereturnFeeEntity> wrapper = new QueryWrapper<>();
        String batchNo=(String)params.get("batchNo");
        wrapper.eq(StringUtils.isNotBlank(batchNo),"batch_no",batchNo);
        wrapper.gt("return_fee",0);
        wrapper.eq("tenant_code", TenantContext.getTenantCode(SecurityUser.getUser()));
        return wrapper;
    }

    @Override
    public int deleteByBatchNo(String batchNo, UserDetail userDetail) {
        QueryWrapper<AftersalePurchasereturnFeeEntity> wrapper = new QueryWrapper<>();
        wrapper.gt("return_fee",0);
        wrapper.eq(StringUtils.isNotBlank(batchNo),"batch_no",batchNo);
        wrapper.eq("tenant_code",userDetail.getTenantCode());
        return baseDao.delete(wrapper);
    }
}